package com.zhf.JDBC01;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 * @Author: ZhaoHuanfeng
 * @Date: 2020/9/22 22:27
 */
public class JDBCDemo01 {

    public static void main(String[] args) throws Exception {


        //注册驱动(可以省略)
        Class.forName("com.mysql.jdbc.Driver");

        //获取连接
        String url="jdbc:mysql://localhost:3306/db4?characterEncoding=UTF-8";
        Connection con=DriverManager.getConnection(url,"root","12345");

        //打印连接对象
        System.out.println(con);

        //获取语句执行平台statement
        Statement statement = con.createStatement();

        //通过statement对象的executeupdate方法创建一张表
        String sql="create table test(id int , name varchar(20) , age int);";
        //返回值是int类型 表示受影响的行数
        int i = statement.executeUpdate(sql);
        System.out.println(i);

        //关闭流
        statement.close();
        con.close();
    }
}
